#include "UILabel.h"

namespace ds {

// =======================================================
// The label UI control implementation
// =======================================================
UILabel::UILabel(UIDialog *dialog,uint32 ID,const std::string& label) : UIControl(dialog,ID) , m_Label(label) {
	m_Dialog->getTextNode()->setText(string::to_string(m_ID),Vec2(0,0),"%s",m_Label.c_str());
	m_Dialog->getTextNode()->calculateSize(string::to_string(m_ID),m_CalculatedSize);
}

void UILabel::align(const Vec2& gridPosition) {
	m_Position = gridPosition;
	m_Dialog->getTextNode()->setText(string::to_string(m_ID),m_Position,"%s",m_Label.c_str());
}

void UILabel::setText(const std::string& label) {
	m_Label = label;	
	m_Dialog->getTextNode()->setText(string::to_string(m_ID),m_Position,"%s",m_Label.c_str());
	m_Dialog->getTextNode()->calculateSize(string::to_string(m_ID),m_CalculatedSize);
}

void UILabel::setText(char* format,...) {
	va_list args;
	va_start(args,format);		
	setText(format,args);
	va_end(args);
}

void UILabel::setText(char* format,va_list args) {
	char buffer[1024];
	int written = vsnprintf_s(buffer,1023,1024,format,args);	
	buffer[1023] = '\0';		
	m_Label = std::string(buffer);
	setText(m_Label);
}

}
